package com.rfsp.demo.listener;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * 基于ServletContextListener的Listener
 *
 * @author zifangsky
 * @date 2018/8/13
 * @since 1.0.0
 */
//@WebListener
public class DemoListener implements ServletContextListener {

    @Autowired
//    private UserMapper userMapper;

    @Override
    public void contextInitialized(ServletContextEvent event) {
    	
//    	 String displayName = event.getApplicationContext().getDisplayName();
//         if(displayName.contains("FeignContext") || displayName.contains("SpringClientFactory")) {
//             return;
//         }
         
    	ServletContext application = event.getServletContext();
        WebApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(application);
//        context.getAutowireCapableBeanFactory().autowireBean(this);
        System.out.println("*************ServletContextListener start************");

//        User user2 = userMapper.selectByUsername("zifangsky");
//        System.out.println(JsonUtils.toJson(user2));
        
    }

    @Override
    public void contextDestroyed(ServletContextEvent event) {
        System.out.println("*************ServletContextListener stop************");
    }
}
